package com.wolfalpha.utron.ui;

import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.wolfalpha.utron.R;

/**
 * Created by luodon on 15/8/17.
 */
public class UIDialog extends DialogFragment{

    private String msg = "消息";

    private OnUIDialogListener mListener;

    /**
     * 对外的接口
     */
    public interface OnUIDialogListener{
        //当点击取消取消
        public void onCancel();
        //当点击确认
        public void onSure();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

        View view = inflater.inflate(R.layout.fragment_dialog,container,false);

        TextView tvMsg = (TextView) view.findViewById(R.id.tv_message);
        Button btnSure = (Button) view.findViewById(R.id.btn_sure);
        Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);

        tvMsg.setText(msg);

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onCancel();
            }
        });
        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onSure();
            }
        });

        return view;
    }

    public void setOnUIDialogListener(OnUIDialogListener listener){
        this.mListener = listener;
    }

    /**
     * 设置消息内容
     * @param message
     */
    public void setMessage(String message){
        this.msg = message;
    }
}
